/**
 * 
 */
package org.pump.client.codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.pump.client.type.RowValue;
import org.pump.client.type.Varstr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liudong03
 *
 */
public class RotateEvent extends EventData{
	private static final Logger mylog = LoggerFactory
			.getLogger(RotateEvent.class);
	long next_binlog_event_pos;
	Varstr next_binlog_file_name;
	int length;
	
	public static RotateEvent readBuffer(IoBuffer in,int len)
	{
		if(in.remaining() < len)
		{
			return null;
		}
		RotateEvent myevent = new RotateEvent();
		myevent.next_binlog_event_pos = in.getLong();
		myevent.length += 8;
		myevent.next_binlog_file_name = Varstr.readBuffer(in, len - myevent.length, RowValue.charset);
		if(myevent.next_binlog_file_name == null)
		{
			mylog.error("read binlog file name fail");
			return null;
		}
		myevent.length += myevent.next_binlog_file_name.getByteLen();
		return myevent;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "RotateEvent [next_binlog_event_pos=" + next_binlog_event_pos
				+ ", next_binlog_file_name=" + next_binlog_file_name
				+ ", length=" + length + "]";
	}

	/**
	 * @return the next_binlog_event_pos
	 */
	public long getNext_binlog_event_pos() {
		return next_binlog_event_pos;
	}

	/**
	 * @return the next_binlog_file_name
	 */
	public Varstr getNext_binlog_file_name() {
		return next_binlog_file_name;
	}

	

}
